import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/widgets/mk_card_container.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class UserPrivacyRecommandPage extends StatefulWidget {
  const UserPrivacyRecommandPage({Key? key}) : super(key: key);

  @override
  State<UserPrivacyRecommandPage> createState() =>
      _UserPrivacyRecommandPageState();
}

class _UserPrivacyRecommandPageState extends State<UserPrivacyRecommandPage> {
  final controller = Get.find<UserPrivacyRecommandController>();
  final state = Get.find<UserPrivacyRecommandController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
        child: Scaffold(
      backgroundColor: Colors.transparent,
      appBar: TDNavBar(
        backgroundColor: Colors.transparent,
        title: '个性化推荐设置',
      ),
      body: Padding(
        padding: EdgeInsets.only(
          left: AppTheme.iDefaultPadding,
          right: AppTheme.iDefaultPadding,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _buildNav(),
            Gaps.vGap24,
            Text('设置推荐偏好'),
            Gaps.vGap12,
            _buildNav2()
          ],
        ),
      ),
    ));
  }

  _buildNav() {
    return MkCardContainer(
      padding: EdgeInsets.symmetric(horizontal: AppTheme.iDefaultPadding / 2),
      margin: EdgeInsets.symmetric(),
      borderRadius: AppTheme.iBorderRadius,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          TDCell(
            title: '个性化推荐',
            description: '关闭后将无法看到个性化推荐的内容',
            style: TDCellStyle(
              descriptionStyle: TextStyle(color: Colors.grey, fontSize: 12),
            ),
            arrow: false,
            rightIconWidget: Obx(() => TDSwitch(
                  isOn: state.recommandStatus,
                  onChanged: controller.updateRecommandStatus,
                  trackOnColor: Colors.blueAccent,
                  trackOffColor: Colors.grey,
                )),
          ),
        ],
      ),
    );
  }

  _buildNav2() {
    return MkCardContainer(
      padding: EdgeInsets.symmetric(horizontal: AppTheme.iDefaultPadding / 2),
      margin: EdgeInsets.symmetric(),
      borderRadius: AppTheme.iBorderRadius,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          TDCell(
            title: '基于所在位置的个性化推荐',
            description: '允许我们使用你的位置信息向你推荐相关内容',
            style: TDCellStyle(
              descriptionStyle: TextStyle(color: Colors.grey, fontSize: 12),
            ),
            rightIconWidget: Obx(() => TDSwitch(
                  isOn: state.positionRecommand,
                  onChanged: controller.updatePositionRecommand,
                  trackOnColor: Colors.blueAccent,
                  trackOffColor: Colors.grey,
                )),
          ),
          TDCell(
            title: '基于搜索记录的个性化推荐',
            description: '允许我们使用历史搜索记录向你推荐相关内容',
            style: TDCellStyle(
              descriptionStyle: TextStyle(color: Colors.grey, fontSize: 12),
            ),
            rightIconWidget: Obx(() => TDSwitch(
                  isOn: state.historyRecomand,
                  onChanged: controller.updateHistoryRecomand,
                  trackOnColor: Colors.blueAccent,
                  trackOffColor: Colors.grey,
                )),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<UserPrivacyRecommandController>();
    super.dispose();
  }
}
